<template>
  <div>
    <search-control :searh-bar="searhBar" @search="search" />
    <warehouse-table v-if="tableType === 'warehouse'" :ref="tableType" />
    <location-table v-if="tableType === 'location'" :ref="tableType" />
    <goods-table v-if="tableType === 'goods'" :ref="tableType" />
    <goods-type-table v-if="tableType === 'goodsType'" :ref="tableType" />
  </div>
</template>
<script>
import searchControl from '@/components/SearchControl'
import warehouseTable from './warehouseTable.vue'
import locationTable from './locationTable.vue'
import goodsTable from './goodsTable.vue'
import goodsTypeTable from './goodsTypeTable.vue'
export default {
  components: { searchControl, warehouseTable, locationTable, goodsTable, goodsTypeTable },
  props: {
    searhBar: { type: Array, required: true },
    tableType: { type: String, required: true }
  },
  methods: {
    // 改值
    changevalue(name, value) {
      const index = this.searhBar.findIndex(item => item.name === name)
      this.searhBar[index].value = value
    },
    // 重置
    resetvalue() {
      this.searhBar.forEach(item => {
        item.value = ''
      })
    },
    // 搜索 点击搜素按钮获取表单组件的值
    search() {
      const querys = this.searhBar.map(item => item.value)
      this.$refs[this.tableType].getData(querys)
    }
  },
  provide() {
    return {
      changevalue: this.changevalue,
      resetvalue: this.resetvalue
    }
  }
}
</script>
<style scoped lang="scss"></style>
